package com.woniuxy.controller;

import com.woniuxy.dao.CampRepo;
import com.woniuxy.entity.Camp;
import com.woniuxy.service.CampService;
import com.woniuxy.service.CoordinateService;
import com.woniuxy.service.ImgService;
import com.woniuxy.util.Result;
import com.woniuxy.vo.CampVO;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class CampController {
    @Resource
    private CampService campService;
    @Resource
    private ImgService imgService;
    @Resource
    private CoordinateService coordinateService;
    @Resource
    private CampRepo campRepo;

    @RequestMapping("/camp/selectAll")
    @CrossOrigin
    public Result selectAllCamp() throws Exception{
        return new Result("200","success",null,campService.selectAllCamp());
    }
    @RequestMapping("/camp/selectbyExample")
    @CrossOrigin
    public Result selectAllCamp(String cityName,String name) throws Exception{
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("cityName",cityName);
        map.put("name",name);
        List<CampVO> list = campService.selectCampByExample(map);
        return new Result("200","success",null,list);
    }
    @RequestMapping("/camp/selectbyCampId")
    @CrossOrigin
    public Result selectbyCampId(Integer campId) throws Exception{
        return new Result("200","success",campService.selectCampByCampId(campId),null);
    }
    @RequestMapping("/camp/selectCampImgByCampId")
    @CrossOrigin
    public Result selectCampImgByCampId(Integer campId) throws Exception{
        return new Result("200","success",null,imgService.selectCampImgByCampId(campId));
    }
    //查询营地坐标
    @RequestMapping("/camp/selectAllCoordinate")
    @CrossOrigin
    public Result selectAllCoordinate() throws Exception{
        return new Result("200","success",null,coordinateService.selectAllCoordinate());
    }
    //根据营地名查询坐标
    //查询营地坐标
    @RequestMapping("/camp/selectNavigation")
    @CrossOrigin
    public Result selectNavigation(String campName) throws Exception{
        return new Result("200","success",null,coordinateService.selectByCampName(campName));
    }

    @RequestMapping("/camp/elasticsearch")
    @CrossOrigin
    public Result selectByElasticsearch(String kw) throws Exception{
        System.out.println("kw="+kw);
        List<CampVO> list = campRepo.selectCampByExampleES(kw);
        return new Result("200","success",null,list);
    }
}
